﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sample.Messages;
using SimpleServiceBus.Bus.MessageManagement.MessageHandling;

namespace SampleConsumer.Handlers {
    public class SquareRequestHandler : IMessageHandler<SquareRequest> {

        public void Handle(SquareRequest message, SimpleServiceBus.Bus.Pipeline.IMessageContext context) {
            Logger.Log("Received request to calculate square of {0}", message.Value);
            if(message.DoNotAnswer) {
                Logger.Log("  but we won't send any response.");
            }
            else
            {
                var _result = new SquareResponse {
                    Result = message.Value * message.Value
                };
                Logger.Log("  sending response of square of {0} = {1}", message.Value, _result.Result);
                context.Endpoint.MessageBus.Reply(_result);
            }
        }

    }
}
